from urllib import request

header={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'}

# 添加请求头
res=request.Request('https://www.baidu.com',headers=header)
resp=request.urlopen(res)
print(resp.read())